import db from '../utils/dbconf'
import { SQL_ERROR } from '../server.config.js'
const TABLE_NAME = 'major'

export default{
  sync: async ({body:{majors}},res) => {
    try {
      let data = {}
      for(let name of majors){
        const id = await db.table(TABLE_NAME).thenAdd({name},{name},false)
        data[name] = id
      }
      return res.send({
        code:200,
        data
      })
    } catch (error) {
      return res.send(SQL_ERROR)
    }
  },
}